package com.gill.touka.rest;

import com.gill.touka.rest.interceptor.TokenRelayRestTemplateInterceptor;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;

import javax.validation.constraints.Max;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Configuration
public class RestConfig {

    @Bean
    @LoadBalanced//整合ribbon
    @SentinelRestTemplate//整合sentinel
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        List<ClientHttpRequestInterceptor> list = new ArrayList<>(1);
        list.add(new TokenRelayRestTemplateInterceptor());//设置拦截器
        restTemplate.setInterceptors(list);
        return restTemplate;
    }
}
